package team.gzjmzy.web.controller;

import java.util.List;
import java.util.Arrays;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import team.gzjmzy.common.annotation.Log;
import team.gzjmzy.common.core.controller.BaseController;
import team.gzjmzy.common.core.domain.AjaxResult;
import team.gzjmzy.common.enums.BusinessType;
import team.gzjmzy.system.domain.entity.TBook;
import team.gzjmzy.system.service.ITBookService;
import team.gzjmzy.common.utils.poi.ExcelUtil;
import team.gzjmzy.common.core.page.TableDataInfo;

/**
 * 图书馆里Controller
 * 
 * @author gzjmzy
 * @date 2021-08-05
 */
@RestController
@RequestMapping("/system/book")
public class TBookController extends BaseController {

    @Autowired
    private ITBookService iTBookService;

    /**
     * 查询图书馆里列表
     */
    @PreAuthorize("@ss.hasPermi('system:book:list')")
    @GetMapping("/list")
        public TableDataInfo list(TBook tBook) {
        startPage();
        List<TBook> list = iTBookService.queryList(tBook);
        return getDataTable(list);
    }
    @PostMapping("/changeStatus")
    public AjaxResult postStatus(@RequestBody TBook tBook){
        return AjaxResult.success(iTBookService.postStatus(tBook));
    }

    /**
     * 获取图书馆里详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:book:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) String id) {
        return AjaxResult.success(iTBookService.queryById(id));
    }

    /**
     * 新增图书馆里
     */
    @PreAuthorize("@ss.hasPermi('system:book:add')" )
    @Log(title = "新增图书馆里" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBook tBook) {
        return toAjax(iTBookService.add(tBook));
    }

    /**
     * 修改图书馆里
     */
    @PreAuthorize("@ss.hasPermi('system:book:edit')" )
    @Log(title = "修改图书馆里" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBook tBook) {
        return toAjax(iTBookService.edit(tBook));
    }


    /**
     * 删除图书馆里
     */
    @PreAuthorize("@ss.hasPermi('system:book:remove')" )
    @Log(title = "删除图书馆里" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(iTBookService.delByIds(Arrays.asList(ids)));
    }

    /**
     * 导出图书馆里列表
     */
    @PreAuthorize("@ss.hasPermi('system:book:export')" )
    @Log(title = "导出图书馆里列表" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(TBook tBook) {
        List<TBook> list = iTBookService.queryList(tBook);
        ExcelUtil<TBook> util = new ExcelUtil<TBook>(TBook.class);
        return util.exportExcel(list, "book" );
    }
}
